package com.of.controller;

import com.of.pojo.Item;

import com.of.pojo.Role;
import com.of.service.ItemService;
import com.of.vo.ItemVo;
import com.of.vo.PageResult;
import com.of.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("/getItemList")
    public SysResult getItemList(PageResult pageResult){
       pageResult= itemService.getItemList(pageResult);
       return SysResult.success(pageResult);
    }

    @PostMapping("/saveItem")
    //@RequestBody注解只有在post请求中才会用到
    //作用是将前端传过来的json串转化为java对象
    public SysResult saveItem(@RequestBody ItemVo itemVo){
        itemService.saveItem(itemVo);
        return SysResult.success();
    }

    @DeleteMapping("/deleteItemById")
    public SysResult deleteItemById(Integer id){
        itemService.deleteItemById(id);
        return SysResult.success();
    }
    @PutMapping("/updateItemStatus")
    public SysResult updateStatus(Item item){
        itemService.updateStatus(item);
        return SysResult.success();
    }

    @PutMapping("/updateItem")
    public SysResult updateRole(@RequestBody Item item){
        itemService.updateItem(item);
        return SysResult.success();
    }
    @GetMapping("/{id}")
    public SysResult findItemById(@PathVariable Integer id){
        Item item = itemService.findItemById(id);
        return SysResult.success(item);
    }
}
